class Solution {
public:
    int strStr(string haystack, string needle) {

        int ll = haystack.size();
        int rl = needle.size();
        if (ll ==0 && rl ==0) {
            return 0;
        } else if (ll == 0) {
            return -1;
        } else if (rl == 0){
            return 0;
        }

        if (ll < rl) {
            return -1;
        }

        int i=0;
        while(i<ll) {
            int j=0;
            int k = i;
            if (haystack[k] == needle[j]) {
                while(k<ll && j<rl) {
                    if (haystack[k] != needle[j]) {
                        break;
                    }
                    k++;
                    j++;
                }
                if (j==rl) {
                    return i;
                }
            }
            i++;
            if (ll - i < rl) {
                break;
            }
        }

        return -1;

    }
};

